<?php
require_once "../funciones.php";
$caweb = con_caweb();
?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link type="text/css" href="../css/redmond/jquery-ui-1.8.2.custom.css" rel="stylesheet" />
        <link rel="stylesheet" type="text/css" media="screen" href="../css/ui.jqgrid.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="../css/ui.multiselect.css" />
        <script src="../js/jquery.js" type="text/javascript"></script>
        <script src="../js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
        <script src="../js/i18n/grid.locale-sp.js" type="text/javascript"></script>
        <script src="../js/jquery.jqGrid.min.js" type="text/javascript"></script>
        <script src="../js/ui.multiselect.js" type="text/javascript"></script>
        <title></title>
        <style>
            .barra{
                font-weight: bolder;
                
                color: #cd0a0a;
}
        </style>
        <script>
            jQuery(document).ready(function(){
                $("#fecIni").datepicker({dateFormat:"yy-mm-dd"});
                $("#fecFin").datepicker({dateFormat:"yy-mm-dd"});
                jQuery("#multiple37").jqGrid({
                    url:'pruebas',
                    datatype: "xml",
                    colNames:['Item','Marca','OC','Factura','Fecha','Cantidad','Proveedor','Valor Unidad','Valor Total','Sucursal'],
                    colModel:[
                        {name:'item',index:'item', width:150},
                        {name:'marca',index:'marca', width:145},
                        {name:'oc',index:'oc', width:80,align: 'center',edittype:'select'},
                        {name:'factura',index:'factura', width:110},
                        {name:'fecha',index:'fecha', width:110, editrules:{date:true}, align: 'center'},
                        {name:'cantidad',index:'cantidad', width:90, sorttype:"int", align: 'center'},
                        {name:'pro.nombre',index:'pro.nombre', width:300},
                        {name:'preciocompra',index:'preciocompra', width:130,align: 'right',formatter:'currency', sorttype:"float"},
                        {name:'total',index:'total', width:130,align: 'right',formatter:'currency', sorttype:"float"},
                        {name:'sucursal',index:'sucursal', width:120,align: 'center',editrules:{integer:true}}
                    ],
                    rowNum:30,
                    mtype: "POST",
                    rowList:[30,50,100],
                    viewrecords: true,
                    rownumbers: true,
                    gridview : true,
                    sortorder: "desc",
                    pager: '#pmultiple37',
                    sortname: 'item',
                    viewrecords: true,
                    height: '80%',
                    toolbar: [true,"top"],
                    caption:"Ordenes de compra",
                    loadComplete: function() {
                        var udata = $("#multiple37").jqGrid('getUserData');
                        $("#t_multiple37").css("font-size","100%").html("Total Unidades:<span class='barra'> "+udata.tcantidad + "</span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Valor Total: <span class='barra'>" + udata.tvalor + "</span> &nbsp;&nbsp;&nbsp;");
                        $("#t_multiple37").css("text-align","right");
                    }
                });

                jQuery("#multiple37").jqGrid('navGrid','#pmultiple37',{edit:false,add:false,del:false,search:true,refresh:true }, {},{},{},{multipleSearch:true});
                //$("#t_multiple37").append("");

                $("#buscar").click(function(){
                    var urla = "scpconsultaCompras.php?q=1\&fecIni=" + $("#fecIni").val() + "\&fecFin=" + $("#fecFin").val() + "\&prove=" + $("#prove").val();
                    jQuery("#multiple37").jqGrid('setGridParam',{url: urla}).trigger("reloadGrid");
                });

    $("#nuevo").click(function(){
        location.reload();
    });

            }); //fin ready

                function avanzado(){
                    jQuery("#multiple37").jqGrid('searchGrid',{multipleSearch:true});
                }

            function mayusculas(obj){
                obj.attr("value",obj.val().toUpperCase());
            }

        </script>
    </head>
    <body>
        <center>
            <table>
                <caption>
                    CONSULTA DE ORDENES DE COMPRA
                </caption>
                <tr>
                    <td><label for="fecIni">Fecha Inicial</label></td>
                    <td><input type="text" name="fecIni" id="fecIni" size="8" /></td>
                    <td><label for="fecFin">Fecha Final</label></td>
                    <td><input type="text" name="fecFin" id="fecFin" size="8" /></td>
                </tr>
                <tr>
                    <td><label for="prove">Proveedor</label></td>
                    <td colspan="3">
                        <div id="dprove">
                        <select name="prove" id="prove">
                            <option value="">Todos</option>
                            <?php
                            $sql = "select * from proveedores order by nombre";
                            $result = mysql_query($sql, $caweb);
                            while ($prove = mysql_fetch_array($result)) {
                                echo "<option value='" . $prove[nit] . "'>$prove[nombre]</option>";
                            }
                            ?>
                        </select>
                            </div>
                    </td>
                </tr>
                <tr align="center">
                    <td colspan="4">
                        <input type='button' value='BUSQUEDA AVANZADA' style='font-size:12px;font-weight: bold;'  onclick='return avanzado();' />
                        <input type="button" value="Buscar" id="buscar"/>
                    </td>
                </tr>
            </table>
            <div id="grilla" style="display: block;">
                <table id="multiple37"></table>
                <div id="pmultiple37" ></div>
            </div>
        </center>
    </body>
</html>
